<?php
class OrderBoardRewardVo extends SzAbstractMySqlVo
{

    private $userId;
    private $position;
    private $orderId;
    private $reward;
    private $extraDrop;
    private $isBonus;

    /**
     * Initialize OrderBoardRewardVo.
     *
     * @param $userId
     * @param $position
     * @param $orderId
     * @param $reward
     * @param $extraDrop
     * @param $isBonus
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return OrderBoardRewardVo
     */
    public function __construct($userId, $position, $orderId, $reward, $extraDrop, $isBonus, $isInsert = false) {
        $this->userId = $userId;
        $this->position = $position;
        $this->orderId = $orderId;
        $this->reward = json_decode($reward, true);
        $this->extraDrop = json_decode($extraDrop, true);
        $this->isBonus = $isBonus;

        $this->isInsert = $isInsert;
        $this->voClassName = 'OrderBoardRewardVo';
        $this->ormName = 'OrderBoardReward';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'position' => $this->getPosition(),
            'orderId' => $this->getOrderId(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
            'extraDrop' => ($needEncode) ? $this->getExtraDrop() : $this->getRawExtraDrop(),
            'isBonus' => $this->getIsBonus(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'position' => $this->getPosition(),
            'orderId' => $this->getOrderId(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
            'extraDrop' => ($needEncode) ? $this->getExtraDrop() : $this->getRawExtraDrop(),
            'isBonus' => $this->getIsBonus(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getPosition(),
            $this->getOrderId(),
            $this->getReward(),
            $this->getExtraDrop(),
            $this->getIsBonus(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getPosition()
    {
        return $this->position;
    }

    public function setPosition($val)
    {
        $this->saveColumnStatus(1, $this->position);
        $this->position = $val;
    }

    public function getOrderId()
    {
        return $this->orderId;
    }

    public function setOrderId($val)
    {
        $this->saveColumnStatus(2, $this->orderId);
        $this->orderId = $val;
    }

    public function getReward()
    {
        return json_encode($this->reward);
    }

    public function getRawReward()
    {
        return $this->reward;
    }

    public function setReward($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[OrderBoardRewardVo] The length of column reward exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('OrderBoardRewardVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[OrderBoardRewardVo] The length of column reward exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(3, $this->reward);
        $this->reward = $val;
    }

    public function getExtraDrop()
    {
        return json_encode($this->extraDrop);
    }

    public function getRawExtraDrop()
    {
        return $this->extraDrop;
    }

    public function setExtraDrop($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 21840) {
            SzLogger::get()->error('[OrderBoardRewardVo] The length of column extraDrop exceed the limit, length / limit: ' . $encodedLength . ' / 21840');
            throw new SzException(10522, array('OrderBoardRewardVo', '21840', $encodedLength));
        } else if ($encodedLength > 19656) {
            SzLogger::get()->warn('[OrderBoardRewardVo] The length of column extraDrop exceed the warning level, length / limit: ' . $encodedLength . ' / 21840');
        }
        $this->saveColumnStatus(4, $this->extraDrop);
        $this->extraDrop = $val;
    }

    public function getIsBonus()
    {
        return $this->isBonus;
    }

    public function setIsBonus($val)
    {
        $this->saveColumnStatus(5, $this->isBonus);
        $this->isBonus = $val;
    }

}